<?php

class ResearchController extends Controller
{
	public function actionIndex()
	{          
		
		$this -> render('index',array(	
                    'title1' => 'hello vh'
		));
	}
        
        public function actionCalendar()
	{          
		
		$this -> render('calendar',array(	                    
		));
	}
        
        public function actionDatePicker()
	{          
            $this ->registerExtjs();	
            
            $this -> render('datepicker',array(	                    
            ));
	}
        
        public function actionJHtmlArea()
        {
            $this -> render('jHtmlArea',array(	                    
            ));
        }
        
        public function actionDesktop()
        {
           // $this ->registerExtjs();
            
            $this -> render('desktop', array());
        }
        
        public function actionCurl()
        {
            $ch = curl_init();
            
            $url = 'http://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx';
            
            $output = Api::getCurrency();
            
            echo $output['Buy'] . " - " . $output['Sell'];
            
            /*
            $this -> render('curl',array(	                    
            ));
             */
        }
        
        	public function ActionUpload()
	{
		if(isset($_GET['qqfile']))
		{
			$sessionID = Yii::app() -> getSession() -> getSessionID();
			
			$tempPath = realpath(Yii::app() -> basePath . '/../files') . '/temp/' . $sessionID;
			$fileName = $_GET['qqfile']; 
			
			$fileSize = 0;
			if (isset($_SERVER["CONTENT_LENGTH"])){
				$fileSize = (int)$_SERVER["CONTENT_LENGTH"];
			}
			
			if (!is_dir($tempPath)) {
				mkdir($tempPath);
			}
			
			$path = $tempPath . '/' . $fileName;
			
			$input = fopen("php://input", "r");
	        $temp = tmpfile();
	        $realSize = stream_copy_to_stream($input, $temp);
	        fclose($input);
	        	     
	        
	        $target = fopen($path, "w");        
	        fseek($temp, 0, SEEK_SET);
	        stream_copy_to_stream($temp, $target);
	        fclose($target);
			
	        echo CJSON::encode(array(
	        	'success' => 'true',
	        	'filename' => $path,
				'size' => $fileSize	        		        	
	        ));
		}
		else
		{
			 echo CJSON::encode(array(
	        	'success' => 'false',
	        	'error' => 'Has no file!'
	        ));
		}
	}
}
